package com.socialuni.center.web.serive;

import com.socialuni.center.web.manage.ThirdUserTokenDOCreate;
import com.socialuni.center.web.model.BO.UserDetailBO;
import com.socialuni.center.web.model.VO.AppInitDataVO;
import com.socialuni.center.web.utils.DevAccountUtils;
import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.platform.qq.QQConst;
import com.socialuni.sdk.platform.weixin.WxConst;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author qinkaiyuan
 * @date 2020-04-12 2:27
 */
@Service
public class LoginService {
    @Resource
    ThirdUserTokenDOCreate thirdUserTokenDOCreate;

    public AppInitDataVO getUserInitData(UserDO user, boolean isLogin) {
        AppInitDataVO appInitData = new AppInitDataVO();
        Integer devId = DevAccountUtils.getDevId();
        //是否为登陆接口，登陆接口返回token信息
        /*if (isLogin) {
            Long devNum = DevAccountUtils.getDevNum();
            //生成userToken
            String userToken = CommonTokenUtil.generateTokenByUserKey(user.getId().toString());

            DevAccountDO devAccountDO = devAccountDOCheck.checkApplyAuthQO(authVO);
            ThirdUserTokenDO tokenDO = thirdUserTokenDOCreate.create(user.getId(), devAccountDO);
            appInitData.setTokenCode(tokenDO.getTokenCode());
        }*/
        //user
        appInitData.setUser(new UserDetailBO(user, true).toVO());
        //notifies
//        List<NotifyDO> notifyDOS = notifyRepository.findTop20ByReceiveUserIdAndTypeInOrderByHasReadDescIdDesc(user.getId(), NotifyType.comments);
//        appInitData.setNotifies(UnreadNotifyVO.unreadNotifyDOToVOS(notifyDOS, user));
        //userDistricts
        /*List<DistrictVO> userDistrictVOS = DistrictVO.districtDOToVOS(districtDOS.stream()
                .map(userDistrictDO -> {
                    return DistrictUtils.get(userDistrictDO.getDistrictId());
                })
                .collect(Collectors.toList()));*/
//        appInitData.setUserDistricts(userDistrictVOS);
        //chats
//        List<ChatVO> chatVOs = chatUserService.getChats(user);
//        appInitData.setChats(chatVOs);
        //微信订阅模板
        appInitData.setTalkTemplateIds(WxConst.talkTemplateIds);
        appInitData.setMessageTemplateIds(WxConst.messageTemplateIds);
        appInitData.setCommentTemplateIds(WxConst.commentTemplateIds);
        appInitData.setReportTemplateIds(WxConst.reportTemplateIds);

        //微信新版订阅模板
        appInitData.setWx_talkTemplateId(WxConst.talk_template_id);
        appInitData.setWx_commentTemplateId(WxConst.comment_template_id);
        appInitData.setWx_reportResultTemplateId(WxConst.report_result_template_id);
        appInitData.setWx_violationTemplateId(WxConst.violation_template_id);

        //qq订阅模板
        appInitData.setQq_talkTemplateId(QQConst.talk_template_id);
        appInitData.setQq_commentTemplateId(QQConst.comment_template_id);
        appInitData.setQq_reportResultTemplateId(QQConst.report_result_template_id);
        appInitData.setQq_violationTemplateId(QQConst.violation_template_id);
        return appInitData;
    }
}
